"""
从0开始3D绘
"""
import matplotlib
from matplotlib import pyplot as plt
import numpy as np

matplotlib.use("TkAgg")

# 定义坐标轴
fig = plt.figure()
ax = plt.axes(projection='3d')


# 绘制坐标轴
def draw_3d():
    plt.show()


# 绘制曲线与散点
def draw_curve():
    z = np.linspace(0, 13, 1000)
    x = 5 * np.sin(z)
    y = 5 * np.cos(z)
    zd = 13 * np.random.random(100)
    xd = 5 * np.sin(zd)
    yd = 5 * np.cos(zd)
    ax.scatter(xd, yd, zd, cmap='b')
    ax.plot(x, y, z, 'gray')
    draw_3d()


# 三维曲面
def draw_surface():
    # 定义三维数据
    xx = np.arange(-5, 5, 0.5)
    yy = np.arange(-5, 5, 0.5)
    X, Y = np.meshgrid(xx, yy)
    Z = np.sin(X)+np.cos(Y)
    # 作图
    ax.plot(X, Y, Z, cmap='rainbow')
    draw_3d()


# 程序入口
if __name__ == "__main__":
    # draw_3d()
    # draw_curve()
    draw_surface()
